package com.example.administrator.testc;/**
 * Created by Administrator on 2016/3/12.
 */

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import pri.zey.custom.activity.AManager;
import pri.zey.custom.activity.ActivityBase;
import pri.zey.custom.activity.FragmentBase;

/**
 * >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>类描述
 * >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>属性描述
 * >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>方法描述
 */
public class TestActivity extends ActivityBase {

    private AManager aManager = TestApplication.aManager;
    private Button button1, button2, button3, button4;
    private TextView text;
    private FragmentBase fragment1 = new FragmentBase(){
        @Nullable
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            return inflater.inflate(R.layout.row_test, container, false);
        }

        @Override
        public void onActivityCreated(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            final Button b1 = (Button) getActivity().findViewById(R.id.titleView);
            final Button b2 = (Button) getActivity().findViewById(R.id.contentView);
            b1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    aManager.add(R.id.rlayout2, fragment1);
//                    aManager.hide(fragment1);
//                    aManager.show(fragment1);
//                    aManager.replace(R.id.rlayout,fragment1);
                    b1.setText("fragment1");
                    b2.setText("fragment1");
                }
            });
            b2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    aManager.add(R.id.rlayout2, fragment1);
//                    aManager.hide(fragment1);
//                    aManager.show(fragment1);
//                    aManager.replace(R.id.rlayout,fragment2);
                    b1.setText("fragment2");
                    b2.setText("fragment2");
                }
            });
        }
    };
    private FragmentBase fragment2 = new FragmentBase(){
        @Nullable
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            TextView view = new TextView(getContext());
            view.setText("11111111111111111112" + '\n' + "22222222222222222222");
            return view;
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test_layout);
        aManager.addActivity(this);
        text = (TextView) findViewById(R.id.text);
        text.setText(this.getThisName());
        button1 = (Button) findViewById(R.id.button);
        button2 = (Button) findViewById(R.id.button2);
        button3 = (Button) findViewById(R.id.button3);
        button4 = (Button) findViewById(R.id.button4);
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getApplicationContext(), TestActivity2.class));
            }
        });
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //startActivity(new Intent(gtApplicationContext(), TestActivity.class));
                aManager.replace(R.id.rlayout, fragment1);
            }
        });
        button3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                aManager.replace(R.id.rlayout, fragment2);
            }
        });
        button4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                aManager.finishAll();
            }
        });
//        Log.i("TAGSS", ">>>>>>>>>>>>>>>>>> " + this.getmActivityName());
    }
}
